﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Common;
using System.Data;

namespace Kailua.net.windward.utils.ado.SPList.custom
{
    /// <summary>
    /// A data reader for SharePoint list data providers.
    /// </summary>
    public class SPListDataReader : DbDataReader
    {
        /**
         * Currently (5/17/10) this is a thin wrapper around DataTableReader.
         **/

        /// <summary>
        /// the nesting level of the current row
        /// </summary>
        private int depth = 0;

        private DataTableReader reader;

        /// <summary>
        /// Creates a new SPListDataReader.  This is a thin wrapper around the DataTableReader class.
        /// </summary>
        /// <param name="reader"></param>
        internal SPListDataReader(DataTableReader reader)
        {
            this.reader = reader;
        }

        #region IDataReader Members

        /// <summary>
        /// Closes the reader.
        /// </summary>
        public override void Close()
        {
            reader.Close();
        }
        /// <summary>
        /// Returns the depth of nesting for the current row of the reader.
        /// </summary>
        public override int Depth
        {
            get { return reader.Depth; }
        }
        /// <summary>
        /// Gets the schema table.
        /// </summary>
        /// <returns></returns>
        public override DataTable GetSchemaTable()
        {
            return reader.GetSchemaTable();
        }
        /// <summary>
        /// Indicates if the reader is closed.
        /// </summary>
        public override bool IsClosed
        {
            get { return reader.IsClosed; }
        }
        /// <summary>
        /// Advances the reader to the next result set if any.
        /// </summary>
        /// <returns></returns>
        public override bool NextResult()
        {
            return reader.NextResult();
        }
        /// <summary>
        /// Advances the reader to the next record.
        /// </summary>
        /// <returns></returns>
        public override bool Read()
        {
            return reader.Read();
        }
        /// <summary>
        /// Gets the number of rows inserted, changed, or deleted by execution of the SQL statement.
        /// </summary>
        public override int RecordsAffected
        {
            get { return reader.RecordsAffected; }
        }

        #endregion

        #region IDataRecord Members
        /// <summary>
        /// Returns the number of columns in the current row.
        /// </summary>
        public override int FieldCount
        {
            get { return reader.FieldCount; }
        }
        /// <summary>
        /// Gets the value of the specified column as a bool.
        /// </summary>
        /// <param name="i"></param>
        /// <returns></returns>
        public override bool GetBoolean(int i)
        {
            return reader.GetBoolean(i);
        }
        /// <summary>
        /// Gets the value of the specified column as a byte.
        /// </summary>
        /// <param name="i"></param>
        /// <returns></returns>
        public override byte GetByte(int i)
        {
            return reader.GetByte(i);
        }
        /// <summary>
        /// Reads a stream of bytes starting at the specified column offset into the
        /// buffer as an array starting at the specified buffer offset.
        /// </summary>
        /// <param name="i"></param>
        /// <param name="fieldOffset"></param>
        /// <param name="buffer"></param>
        /// <param name="bufferoffset"></param>
        /// <param name="length"></param>
        /// <returns></returns>
        public override long GetBytes(int i, long fieldOffset, byte[] buffer, int bufferoffset, int length)
        {
            return reader.GetBytes(i, fieldOffset, buffer, bufferoffset, length);
        }
        /// <summary>
        /// Gets the value of the specified column as a char.
        /// </summary>
        /// <param name="i"></param>
        /// <returns></returns>
        public override char GetChar(int i)
        {
            return reader.GetChar(i);
        }
        /// <summary>
        /// Returns the value of the specified column as a character array.
        /// </summary>
        /// <param name="i"></param>
        /// <param name="fieldoffset"></param>
        /// <param name="buffer"></param>
        /// <param name="bufferoffset"></param>
        /// <param name="length"></param>
        /// <returns></returns>
        public override long GetChars(int i, long fieldoffset, char[] buffer, int bufferoffset, int length)
        {
            return reader.GetChars(i, fieldoffset, buffer, bufferoffset, length);
        }
        /// <summary>
        /// Gets a string representing the data type of the specified column.
        /// </summary>
        /// <param name="i"></param>
        /// <returns></returns>
        public override string GetDataTypeName(int i)
        {
            return reader.GetDataTypeName(i);
        }
        /// <summary>
        /// Gets the value of the specified column as a DateTime.
        /// </summary>
        /// <param name="i"></param>
        /// <returns></returns>
        public override DateTime GetDateTime(int i)
        {
            return reader.GetDateTime(i);
        }
        /// <summary>
        /// Gets the value of the specified column as a decimal.
        /// </summary>
        /// <param name="i"></param>
        /// <returns></returns>
        public override decimal GetDecimal(int i)
        {
            return reader.GetDecimal(i);
        }
        /// <summary>
        /// Gets the value of the specified column as a double.
        /// </summary>
        /// <param name="i"></param>
        /// <returns></returns>
        public override double GetDouble(int i)
        {
            return reader.GetDouble(i);
        }
        /// <summary>
        /// Gets the System.Type of the object.
        /// </summary>
        /// <param name="i"></param>
        /// <returns></returns>
        public override Type GetFieldType(int i)
        {
            return reader.GetFieldType(i);
        }
        /// <summary>
        /// Gets the value of the specified column as a float.
        /// </summary>
        /// <param name="i"></param>
        /// <returns></returns>
        public override float GetFloat(int i)
        {
            return reader.GetFloat(i);
        }
        /// <summary>
        /// Gets the value of the specified column as a Guid.
        /// </summary>
        /// <param name="i"></param>
        /// <returns></returns>
        public override Guid GetGuid(int i)
        {
            return reader.GetGuid(i);
        }
        /// <summary>
        /// Gets the value of the specified column as a short.
        /// </summary>
        /// <param name="i"></param>
        /// <returns></returns>
        public override short GetInt16(int i)
        {
            return reader.GetInt16(i);
        }
        /// <summary>
        /// Gets the value of the specified column as a int.
        /// </summary>
        /// <param name="i"></param>
        /// <returns></returns>
        public override int GetInt32(int i)
        {
            return reader.GetInt32(i);
        }
        /// <summary>
        /// Gets the value of the specified column as a long.
        /// </summary>
        /// <param name="i"></param>
        /// <returns></returns>
        public override long GetInt64(int i)
        {
            return reader.GetInt64(i);
        }
        /// <summary>
        /// Gets the value of the specified column as a string.
        /// </summary>
        /// <param name="i"></param>
        /// <returns></returns>
        public override string GetName(int i)
        {
            return reader.GetName(i);
        }
        /// <summary>
        /// Gets the column ordinal, given the name of the column.
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public override int GetOrdinal(string name)
        {
            return reader.GetOrdinal(name);
        }
        /// <summary>
        /// Gets the value of the specified column as a string.
        /// </summary>
        /// <param name="i"></param>
        /// <returns></returns>
        public override string GetString(int i)
        {
            return reader.GetString(i);
        }
        /// <summary>
        /// Gets the value of the specified column as an object.
        /// </summary>
        /// <param name="i"></param>
        /// <returns></returns>
        public override object GetValue(int i)
        {
            return reader.GetValue(i);
        }
        /// <summary>
        /// Gets an array of objects that contains values from the current row.
        /// </summary>
        /// <param name="values"></param>
        /// <returns></returns>
        public override int GetValues(object[] values)
        {
            return reader.GetValues(values);
        }
        /// <summary>
        /// Indicates if the column contains a null value.
        /// </summary>
        /// <param name="i"></param>
        /// <returns></returns>
        public override bool IsDBNull(int i)
        {
            return reader.IsDBNull(i);
        }

        /// <summary>
        /// Gets the value of the specified column in its native format given the column name.
        /// </summary>
        /// <param name="name">the name of the column</param>
        /// <returns></returns>
        public override object this[string name]
        {
            get { return reader[name]; }
        }

        /// <summary>
        /// Gets the value of the specified column in its native format given the column ordinal.
        /// </summary>
        /// <param name="i">The zero-based column ordinal.</param>
        /// <returns></returns>
        public override object this[int i]
        {
            get { return reader[i]; }
        }

        #endregion
        /// <summary>
        /// Gets an enumerator that can be used to iterate through the item collection.
        /// </summary>
        /// <returns></returns>
        public override System.Collections.IEnumerator GetEnumerator()
        {
            return reader.GetEnumerator();
        }
        /// <summary>
        /// Indicates if the reader has one or more rows.
        /// </summary>
        public override bool HasRows
        {
            get { return reader.HasRows; }
        }
    }
}
